package dev.bong.controller;

import dev.bong.dto.LabRepairDTO;
import dev.bong.dto.RegisterDTO;
import dev.bong.pojo.result.Result;
import dev.bong.service.TeacherService;
import dev.bong.utils.ThreadLocalUtil;
import dev.bong.vo.RegisterVO;
import dev.bong.vo.RepairVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author: bong~
 * @description: TODO
 * @date: 2024/4/14 11:20
 * @version: 1.0
 */

@RestController
@Slf4j
@RequestMapping("/teacher")
@Api(tags = "教师模块")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    @GetMapping("/register/list")
    @ApiOperation(value = "登记申请列表",notes = "申请状态: -1:未排课，1:已排课")
    public Result<List<RegisterVO>> getRegisterList(){

        List<RegisterVO> list=teacherService.getRegisterList();

        return Result.success(list);
    }

    @PostMapping("/register/add")
    @ApiOperation(value = "新增登记")
    public Result addRegister(@RequestBody RegisterDTO registerDTO){

        teacherService.addRegister(registerDTO);

        return Result.success("新增登记，成功！");

    }
    @PutMapping("/register/update")
    @ApiOperation(value = "修改登记",notes = "申请状态: -1:未排课，1:已排课")
    public Result updateRegister(@RequestBody RegisterDTO registerDTO){

        Integer registerId=registerDTO.getId();
        Integer registerStatus=teacherService.getRegisterStatusById(registerId);
        if(registerStatus != -1){
            return Result.error("该登记已完成，无法修改！");
        }

        teacherService.updateRegister(registerDTO,registerId);
        return Result.success();
    }

    @GetMapping("/repair/list")
    @ApiOperation(value = "设备报修列表",notes="报修状态：-1:未维修,0:维修中,1:已维修")
    public Result<List<RepairVo>> getRepairList(){

        List<RepairVo> list=teacherService.getRepairList();
        return Result.success(list);
    }



    @PostMapping("/repair/add")
    @ApiOperation(value = "新增报修")
    public Result addRepair(@RequestBody LabRepairDTO dto){


        Integer labId=teacherService.getLabIdByNumber(dto.getLabNumber());

        if(labId==null){
            return Result.error("该实验室不存在");
        }
        teacherService.addRepair(dto);

        return Result.success("新增报修成功");
    }


}
